package com.cet.qz.unit01.chapter1_1;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2020-12-09 22:01
 **/
public class Qz1_1_15 {

    public static int[] histogram(int[] a, int M) {
        int[] b = new int[a.length];
        int[] c = new int[M];
        int times;

        for (int j = 0; j < a.length; j++) {
            times = 0;
            for (int k = 0; k < a.length; k++) {
                if (a[k] == a[j]) {
                    times ++;
                }
            }
            b[j] = times;
        }

        for (int i = 0; i < M; i++) {
            c[i] = b[i];
        }

        return c;
    }

    public static void main(String[] args) {
        int[] a = {1,0,2,1,0,2,1,1,1};
        int[] b = histogram(a,5);
        for (int i : b) {
            System.out.println(i);
        }
    }
}
